package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxLbWzh;
import cn.stylefeng.guns.modular.lx.mapper.LxLbWzhMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxLbWzhParam;
import cn.stylefeng.guns.modular.lx.model.result.LxLbWzhResult;
import  cn.stylefeng.guns.modular.lx.service.LxLbWzhService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wzh
 * @since 2023-12-01
 */
@Service
public class LxLbWzhServiceImpl extends ServiceImpl<LxLbWzhMapper, LxLbWzh> implements LxLbWzhService {

    @Override
    public void add(LxLbWzhParam param){
        LxLbWzh entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxLbWzhParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxLbWzhParam param){
        LxLbWzh oldEntity = getOldEntity(param);
        LxLbWzh newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxLbWzhResult findBySpec(LxLbWzhParam param){
        return null;
    }

    @Override
    public List<LxLbWzhResult> findListBySpec(LxLbWzhParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxLbWzhParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(LxLbWzhParam param){
        return param.getSpId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxLbWzh getOldEntity(LxLbWzhParam param) {
        return this.getById(getKey(param));
    }

    private LxLbWzh getEntity(LxLbWzhParam param) {
        LxLbWzh entity = new LxLbWzh();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }


    @Autowired
    private LxLbWzhMapper lxLbWzhMapper;

    @Override
    public ResponseData list2(LxLbWzhParam lxLbWzhParam) {
        List<LxLbWzhResult> list = lxLbWzhMapper.List2(lxLbWzhParam);
        return ResponseData.success(list);
    }
}
